--[[
EVA Framework 功能演示 demo by simonw

触发条件:
1. 在say频道或party频道输入*hw;
2. 输入SlashCommand, /helloworld或/hw;
3. 点击EvaHelloBB这个button;
4. 按下 "]" 键触发, "[" 键使用炉石
5. 注释掉CustomKeyBinding, 按下 "F" 和 "ALT-H" 键
6. 游戏中按键设置EvaKeyBindingTest按下

触发权限:
自己或自己的朋友

此插件执行情况如下, 屏幕打印, 括号内时间间隔不打印:
(间隔1秒) hello (间隔1秒) hello world (间隔3秒) (间隔1秒) hello (间隔1秒) hello world

输入SlashCommand, /hc, 打印context.
]]

EvaHelloWorld = {}

function EvaHelloWorld.Say1(context)
	DEFAULT_CHAT_FRAME:AddMessage("hello")
	--context.Timer:End()
end

function EvaHelloWorld.Say2()
	DEFAULT_CHAT_FRAME:AddMessage("world-------")
end

function EvaHelloWorld.Say3(context)
	DEFAULT_CHAT_FRAME:AddMessage(
	string.format("RequestType:%s, Slash_Arg:%s", context.RequestType, context.Slash_Arg))
end

function EvaHelloWorld.CustomKeyBinding()
	local testbutton = CreateFrame("CheckButton", "EvaTestbutton1", UIParent, "SecureActionButtonTemplate")
	testbutton:SetAttribute("type1", "evafunc")
	testbutton:SetAttribute("type2", "item")
	testbutton:SetAttribute("item2", "炉石")
	testbutton:SetAttribute("unit", "player")

	testbutton:SetHeight(30)
	testbutton:SetWidth(30)
	testbutton:SetPoint("CENTER")
	testbutton:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-Up")
	testbutton:SetPushedTexture("Interface\\Buttons\\UI-PlusButton-Down")
	testbutton:SetHighlightTexture("Interface\\Buttons\\UI-PlusButton-Hilight")

	SetOverrideBindingClick(testbutton, false, "]", testbutton:GetName())
	SetOverrideBindingClick(testbutton, false, "[", testbutton:GetName(), "RightButton")

	return testbutton
end

function EvaHelloWorld.test1(context)
	DEFAULT_CHAT_FRAME:AddMessage("test1")
	context.Timer:End()
end

function EvaHelloWorld.test2(context)
	DEFAULT_CHAT_FRAME:AddMessage("test2")
end

-------------------- blocks ------------------------
local testBlock = {
	Name = "",
	Description = "",
	RequestTypes = {"SlashCommand"},
	SlashCommands = {"/hhh"},
	Enabled = 1,
	Commands = {
		{Description = "say hello", Function = EvaHelloWorld.test1, Timer = {Interval = 1, Times = -1}},
		{Description = "say world", Function = EvaHelloWorld.test2, Timer = {Interval = 3, Times = 1}},
	}
}

EvaHelloWorld.HelloBlock = {
	Name = "Hello Block",
	Description = "Say hello world",
	RequestTypes = {"EventChatCommand", "SlashCommand", "FrameEvent", "KeyBinding"},
	Events = {"CHAT_MSG_SAY","CHAT_MSG_PARTY"},
	FrameEvents = {"EvaHelloBB:OnMouseUp",},
	SlashCommands = {"/helloworld", "/hw"},
	KeyBindings = {"F", "ALT-H"},
	--CustomKeyBinding = EvaHelloWorld.CustomKeyBinding,
	Permission = {AllowList = {"&Player", "&Friend"}},
	Enabled = 1,
	Commands = {
		ChatCommand = "hw", ThreadMode = "Multi",
		GTimer = {Interval = 3, Times = 2},
		{Description = "say hello", Function = EvaHelloWorld.Say1, Timer = {Interval = 1, Times = 2}},
		{Description = "say world", Function = EvaHelloWorld.Say2, Timer = {Interval = 2, Times = 1}},
	}
}

local helpBlock = EVA.Block:New()
helpBlock.Name = "Help Block"
helpBlock.RequestTypes = {"SlashCommand"}
helpBlock.SlashCommands = {"/hc"}
helpBlock.Enabled = 1
helpBlock.Commands = {{Description = "dump context", Function = EvaHelloWorld.Say3}}


EvaHelloWorldAddon = EVA.Addon:New()
EvaHelloWorldAddon.Name = "EvaHelloWorld"
EvaHelloWorldAddon.Version = "1.2"

EvaHelloWorldAddon:Add(EVA.Block:New(EvaHelloWorld.HelloBlock))
EvaHelloWorldAddon:Add(helpBlock)
EvaHelloWorldAddon:Add(EVA.Block:New(testBlock))

EVA.AddonRegistry:Add(EvaHelloWorldAddon)

--/script EVA.AddonRegistry:Unregister(EvaHelloWorldAddon)
--/script EVA.AddonRegistry:Register(ShortUnitFrameAddon)
--/script print(GetAddOnMetadata("!EVA", "Author"))
--/script DisableAddOn("ShortUnitFrame")